<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.Set"%>
<%@page import="com.taobao.askwho.vo.PersonalPageRecordVo"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="快速找到解决问题的人或资料的网站">
<meta name="author" content="zhongting.zy">
<title>查询结果</title>
<!-- Le styles -->
<link href="<%= request.getContextPath()%>/assets/css/bootstrap.css"
	rel="stylesheet">
<style type="text/css">
body {
	padding-top: 60px;
	padding-bottom: 40px;
}
</style>
<link
	href="<%=request.getContextPath()%>/assets/css/bootstrap-responsive.css"
	rel="stylesheet">

<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->

<!-- Le fav and touch icons -->
<link rel="shortcut icon"
	href="<%= request.getContextPath()%>/assets/ico/favicon.ico">
<link rel="apple-touch-icon-precomposed" sizes="144x144"
	href="<%=request.getContextPath()%>/assets/ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114"
	href="<%=request.getContextPath()%>/assets/ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72"
	href="<%=request.getContextPath()%>/assets/ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed"
	href="<%=request.getContextPath()%>/assets/ico/apple-touch-icon-57-precomposed.png">
</head>
<%
	List<PersonalPageRecordVo> itemList = (List<PersonalPageRecordVo>)request.getAttribute("itemList");
	if(itemList == null)
		itemList = new ArrayList<PersonalPageRecordVo>();
%>
<body>
	<%@include file="/jsp/header.jsp" %>
	<div class="container">
		<div class="row">
			<div class="span12">
			<form class="well form-search" action="<%=request.getContextPath()%>/urljump.do" method="get">
			<div style="float: left;">
			  <input type="hidden" name="method" value="searchMain">
			  <input type="text" class="input-xxlarge search-query" placeholder="支持分词搜素，如输入:百科 url 或  detail person" name="keyword" value="${keyword}" id="keyword1">
			  <button type="submit" class="btn">查询</button>
			  </div>
			  <div style="float: right;">去哪里、去问谁</div>
			</form>
				<table class="table table-striped">
					<thead>
						<tr>
							<th width="55%">内容</th>
							<th width="5%">类型</th>
							<th width="30%">已有的标签</th>
							<th width="10%">
							<div align="center">操作</div>
							</th>
						</tr>
					</thead>
					<tbody>
					<%
						for(PersonalPageRecordVo vo : itemList) {
							String content = "";
							String type = vo.getType(); 
							if(type.equals("url")) {
								content = vo.getUrlInfo().getUrlContent();
							} else if(type.equals("person")){
								content = vo.getPersonInfo().getPersonName() 
										+ "(旺旺:" + vo.getPersonInfo().getWangwang() + ")";
							} else {
								continue;
							}
							Set<String> set = vo.getTagNamesSet();
							String tagLinkContent = "";
							if(vo.getTagNamesSet() != null)
								tagLinkContent = (String)vo.getTagNamesSet().toArray()[0];
							String isPublic = "";
							if(vo.isPublic())
								isPublic = "公开";
							else
								isPublic = "私有";
							String tagIds = vo.getUuid();
					%>
						<tr>
							<td><%=content%></td>
							<td><%=vo.getType()%></td>
							<td><%=tagLinkContent%></td>
							<td>
								<div align="center">
									<button class="btn btn-small btn-info" onclick="collectATag('<%=tagIds%>')">收藏</button>								
								</div>
							</td>
						</tr>						
					<%
						}
					%>
					</tbody>
				</table>
				<!-- 
				<p>
					<a class="btn" href="#">查看更多 &raquo;</a>
				</p>
				 -->
			</div>
		</div>
		<!--/row-->
		<hr>
	<%@include file="/jsp/footer.jsp" %>
	</div>
	<!--/.fluid-container-->

	<!-- Le javascript
    ================================================== -->
	<!-- Placed at the end of the document so the pages load faster -->
	<script src="<%=request.getContextPath()%>/assets/js/jquery.js"></script>
	<script
		src="<%=request.getContextPath()%>/assets/js/bootstrap-transition.js"></script>
	<script
		src="<%=request.getContextPath()%>/assets/js/bootstrap-alert.js"></script>
	<script
		src="<%=request.getContextPath()%>/assets/js/bootstrap-modal.js"></script>
	<script
		src="<%=request.getContextPath()%>/assets/js/bootstrap-dropdown.js"></script>
	<script
		src="<%=request.getContextPath()%>/assets/js/bootstrap-scrollspy.js"></script>
	<script src="<%=request.getContextPath()%>/assets/js/bootstrap-tab.js"></script>
	<script
		src="<%=request.getContextPath()%>/assets/js/bootstrap-tooltip.js"></script>
	<script
		src="<%=request.getContextPath()%>/assets/js/bootstrap-popover.js"></script>
	<script
		src="<%=request.getContextPath()%>/assets/js/bootstrap-button.js"></script>
	<script
		src="<%=request.getContextPath()%>/assets/js/bootstrap-collapse.js"></script>
	<script
		src="<%=request.getContextPath()%>/assets/js/bootstrap-carousel.js"></script>
	<script
		src="<%=request.getContextPath()%>/assets/js/bootstrap-typeahead.js"></script>
    <!-- jquery ui -->
    <link href="<%=request.getContextPath()%>/assets/css/jquery-ui-1.8.18.custom.css" rel="stylesheet">		
    <!-- autocomplete -->
    <script src="<%=request.getContextPath()%>/assets/js/jquery.ui.core.js"></script>
    <script src="<%=request.getContextPath()%>/assets/js/jquery.ui.widget.js"></script>
    <script src="<%=request.getContextPath()%>/assets/js/jquery.ui.position.js"></script>
    <script src="<%=request.getContextPath()%>/assets/js/jquery.ui.autocomplete.js"></script>		
	<script type="text/javascript">
		function collectATag(tagUuid) {
			$.ajax({
				  url: '<%=request.getContextPath()%>/tagopt.do?method=collectATag',
				  dataType: 'json',
				  type: "post",
				  data: {
					  tagUuid: tagUuid
				  },
				  success: function(data) {
					if(data.success) {
						alert("收藏成功");
						//window.location.reload();
					} else {
						alert(data.msg);
						//alert("保存失败");
					}
				  }
				});				
		}	
        $(function () {
            //autocomplete插件
            //缓存
            var cache = {};
            $("#keyword1").autocomplete({
                source:function (request, response) {
                    var term = request.term;
                    if (term in cache) {
                        response($.map(cache[ term ], function (item) {
                            return {
                                value:item.tagName
                            }
                        }));
                        return;
                    }
                    $.ajax({
                        url:"tagopt.do?method=tagAutoCompleted",
                        dataType:"json",
                        data:{
                            q:request.term
                        },
                        success:function (data) {
                            cache[ term ] = data;
                            response($.map(data, function (item) {
                                return {
                                    value:item.tagName
                                }
                            }));
                        }
                    });
                },
                minLength:0,
                select:function (event, ui) {
                    $("#keyword").val(ui.item.tagName);
                }
            });
            
			$('#myTab').click(function (e) {
				alert("sss");
				  e.preventDefault();
				  $(this).tab('show');
			})            
        })	
	</script>
</body>
</html>
